class RaceCar extends UTVehicle_Scorpion_Content placeable;

var float hitTime;
var float hitOn;
var float hitSpeed;
var float normalSpeed;
var() int selectedWeapon;
var bool shieldActivated;
var float shieldActivatedOn;
var float shieldActivatedTime;

var(VehicleCamera) Vector cameraOffset;
var(VehicleCamera) float maxCameraZoom;
var(VehicleCamera) float minCameraZoom;
var() bool FreezePawn;
var() int Ammo;


simulated function PostBeginPlay()
{
	super.PostBeginPlay();	
	
	
	//Weapons[0].CurrentAim = rot(0,32768,0);
	 //`log("-------------> "$TurretRotate);
}


defaultproperties
{
	ControllerClass=class'RaceCombatAi';
	bLookSteerOnNormalControls = true;
	bLookSteerOnSimpleControls = true;
	bAvoidReversing = true;

	hitTime = 0.50;//Tijd van slow in seconden
	cameraOffset=(X= -250,Y= 0,Z= 100);
	maxCameraZoom = 200;
	minCameraZoom = 100;

	selectedWeapon = 1;

	MaxSpeed = 7000;
	AirSpeed = 4000;
	hitSpeed = 10;
	normalSpeed = 5000;
	GroundSpeed = 5000;
	BoostSteerFactors = 0;
	bEjectPassengersWhenFlipped = false;
	
	bCanFlip=true;
	FreezePawn = true;
	//StayUprightRollResistAngle = 145;
	//UprightTime = 1;
	//UprightLiftStrength = 210;
	//UprightTorqueStrength = 30;
	//bStayUpright = true; // houd hem overeind
	bBounce = true;
	bCollideWhenPlacing = false;

	COMOffset=(x=0.0,y=0.0,z=-36.0)

	Begin Object Class=UTVehicleSimCar Name=SimObject
	WheelSuspensionStiffness=100.0
	WheelSuspensionDamping=2.0
	WheelSuspensionBias=0.1
	ChassisTorqueScale=0.0
	MaxBrakeTorque=100.0
	StopThreshold=100
	//AirControlTurnTorque=20;

	LSDFactor=0.0
	EngineBrakeFactor=0.01 //zorgt ervoor dat auto langzaam uitrolt bij gas los
	ThrottleSpeed=100 //zorgt ervoor dat auto langzaam uitrolt bij gas los
	WheelInertia=0.2
	NumWheelsForFullSteering=4
	SteeringReductionFactor=0.05
	SteeringReductionMinSpeed=1
	SteeringReductionSpeed=1
	bAutoHandbrake=false
	bClampedFrictionModel=true
	FrontalCollisionGripFactor=0.18
	ConsoleHardTurnGripFactor=1.0
	HardTurnMotorTorque=0.7 

	SteeringReductionSpeed = 1000
	
	MaxSteerAngleCurve=(Points=((InVal=0,OutVal=45),(InVal=600.0,OutVal=15.0),(InVal=1100.0,OutVal=10.0) ,(InVal=1300.0,OutVal=6.0),(InVal=1600.0,OutVal=5.0),(InVal=3000.0,OutVal=1.0)))
	//SteerSpeed=100
	End Object

	//wMaxAngularVelocity = 1;
	//DriverWeapons(0)=(WeaponClass=class'UTVWeap_Rockets',WeaponBone=PlasmaGunAttachment);
	
	Seats(0)={(	GunClass=class'UTVWeap_Rockets',
				GunSocket=(TurretFireSocket),
				GunPivotPoints=(gun_rotate),
				TurretVarPrefix="",
				TurretControls=(TurretRotate),
				SeatIconPos=(X=	0.415,Y=0.5),
				CameraTag=GunViewSocket,
				CameraBaseOffset=(X=-50.0),
				CameraOffset=-175,
				WeaponEffects=((SocketName=TurretFireSocket,Offset=(X=-14,Y=5),Scale3D=(X=2.0,Y=3.0,Z=3.0)),(SocketName=TurretFireSocket,Offset=(X=-14,Y=-5),Scale3D=(X=2.0,Y=3.0,Z=3.0)))
				)}

	/*uiterlijk*/
	Begin Object Name=SVehicleMesh
		SkeletalMesh=SkeletalMesh'MoleCar4.MolAuto9'//de skeletal mesh
		AnimTreeTemplate=AnimTree'VH_Scorpion.Anims.AT_VH_Scorpion_001' //anim tree
		PhysicsAsset=PhysicsAsset'MoleCar4.Mesh.SK_VH_MoleCar_001_Physics'//'VH_Scorpion.Mesh.SK_VH_Scorpion_001_Physics' // physics
		AnimSets.Add(AnimSet'VH_Scorpion.Anims.K_VH_Scorpion') //anim set
		RBCollideWithChannels=(Default=TRUE,BlockingVolume=TRUE,GameplayPhysics=TRUE,EffectPhysics=TRUE,Vehicle=TRUE,Untitled4=TRUE)
	End Object


	/*sound :) */
	Begin Object Name=ScorpionEngineSound
		SoundCue=SoundCue'racegame_sound.race_sound_cue'
	End Object
	Begin Object Name=ScorpionSquealSound
		SoundCue=SoundCue'racegame_sound.race_slip_sound'
	End Object
	Begin Object Name=ScorpionTireSound
		SoundCue=none
	End Object

	EnterVehicleSound=SoundCue'racegame_sound.Auto_start_cue'
	CollisionSound=none
	ExitVehicleSound=none

	TireSoundList(0)=none
	TireSoundList(1)=none
	TireSoundList(2)=none
	TireSoundList(3)=none
	TireSoundList(4)=none
	TireSoundList(5)=none
	TireSoundList(6)=none
	TireSoundList(7)=none
	TireSoundList(8)=none

	

	//SelfDestructEnabledLoop=SoundCue'A_Vehicle_Scorpion.SoundCues.A_Vehicle_Scorpion_EngineThrustLoop_Cue'
}

event Tick(float d)
{
	//MaxSpeed = 1;
	//AirSpeed = 1;
	if(FreezePawn)
	{
		Throttle = 0;
		return;
	}
	
	MaxSpeed = 7000;

	if(WorldInfo.TimeSeconds > hitOn+hitTime)
	{
		AddForce(Normal(Velocity)*20);	
		AirSpeed = normalSpeed;
	}
	else
	{
		AirSpeed = hitSpeed;
	}

	if(WorldInfo.TimeSeconds > shieldActivatedOn+shieldActivatedTime)
	{
		shieldActivated = false;
	}
}




event TakeDamage(int DamageAmount, Controller EventInstigator, vector HitLocation, vector Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor DamageCauser)
{
	if(DamageCauser!=none && DamageCauser.IsA('UTProj_HomingRocket') && !shieldActivated)
		hitOn = WorldInfo.TimeSeconds;
}

function activateShield(float time){
	`log("shieldActivated");
	shieldActivated = true;
	shieldActivatedOn = WorldInfo.TimeSeconds;
	shieldActivatedTime = time;
}

function selectWeapon(int w){
	selectedWeapon = w;
	
	if(selectedWeapon == 1)
		UTVWeap_Rockets(Seats[0].Gun).AmmoCount = 5;
	else if(selectedWeapon == 2)
		UTVWeap_Rockets(Seats[0].Gun).AmmoCount = 1;
	else
		Seats[0].Gun.AmmoCount = 0;

	Ammo = UTVWeap_Rockets(Seats[0].Gun).AmmoCount;
}

/**
 *	Calculate camera view point, when viewing this actor.
 *
 * @param	fDeltaTime	delta time seconds since last update
 * @param	out_CamLoc	Camera Location
 * @param	out_CamRot	Camera Rotation
 * @param	out_FOV		Field of View
 * @return	true if Actor should provide the camera point of view.
 * @network				Server and client
 */
simulated function bool CalcCamera(float fDeltaTime, out vector out_CamLoc, out rotator out_CamRot, out float out_FOV)
{
	local Vector PotentialCameraLocation, HitLocation, HitNormal;
	local Actor HitActor;

	// Set the location of the camera, use the target's location add it with the camera offset, that is 
	// stored in the camera properties, which has been rotated by the target's rotation.
	PotentialCameraLocation = Location + (cameraOffset >> Rotation);

	// Perform a trace to see if we are interecting world geometry, if it then reset the potential camera location
	// to the hit location which pushed away using the hit normal. This prevents the camera from
	// being within a mesh
	ForEach TraceActors(class'Actor', HitActor, HitLocation, HitNormal, PotentialCameraLocation, Location)
	{
		if (HitActor != None && HitActor.bWorldGeometry)
		{
			PotentialCameraLocation = HitLocation + HitNormal * 8.f;
			break;
		}
	}

	// Set the location of the camera
	out_CamLoc = PotentialCameraLocation;
	// Set the rotation of the camera, by subtracting the target location and the camera location we 
	// find the direction to point the camera at the target.
	out_CamRot = Rotator(Location - out_CamLoc);
	// Return the FOV based on relative 
	if(MaxSpeed == 0)
		MaxSpeed = 7000;
	out_FOV = Lerp(minCameraZoom, maxCameraZoom, VSize(Velocity) / MaxSpeed);

	return true;
}

function traceWall()
{
	local Vector HitLocation;
	local Vector HitNormal;
	local Vector ReturnVector;


	Trace(HitLocation,HitNormal,Location+Normal(Vector(Rotation))*500,Location,true);

	DrawDebugLine(Location,Location+Normal(Vector(Rotation))*500,250,0,0, false);
	DrawDebugLine(HitLocation,HitLocation+HitNormal*500,0,250,0, false);
}